const app = getApp();
Page({
    data: {
        key:'',
        sid:'',
        shop:{},
        StatusBar: app.globalData.StatusBar + 6,
        TabbarBot: app.globalData.tabbar_bottom,
        TabCur: 1,scrollLeft:0,
        SortMenu: [{id:1,name:"综合"},{id:2,name:"销量"},{id:3,name:"新品"},{id:4,name:"价格"}],
        ShopList: [],
    },
    onLoad: function (options) {
        let that = this;
        this.setData({
          sid: options.sid
        })
        this.shopInfo(options.sid)
        this.productList(options.sid, this.data.TabCur)
    },
    tabSelect(e) {
        console.log(e.currentTarget.dataset.id);
        this.setData({
            TabCur: e.currentTarget.dataset.id,
            scrollLeft: (e.currentTarget.dataset.id-1)*60
        })
        this.productList(this.data.sid, e.currentTarget.dataset.id)
    },
    btnback: function () {
        wx.navigateBack();
    },
    search: function (e) {
      console.log(e.detail.value.key)
        wx.navigateTo({
            url: '/pages/shop/search/index?key=' + e.detail.value.key + '&sid=' + this.data.sid
        });
    },
    shopInfo:function(sid){
      wx.request({
        method:'GET',
        url: 'http://localhost:8989/shop/' + sid ,
        success:(res=>{
          this.setData({
            shop: res.data.data
          })
          console.log(res)
        })
      })
    },
    productList:function(sid, saleType){
      wx.request({
        url: 'http://localhost:8989/product/store',
        data:{
          store: sid,
          saleType: saleType
        },
        success:(res => {
          this.setData({
            ShopList: res.data.data
          })
        })
      })
    }
});
